package com.szss.springbootfirst.controller;

import com.szss.springbootfirst.entity.User;
import com.szss.springbootfirst.mq.MessageProducer;
import com.szss.springbootfirst.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author wcx
 * @date 2023/2/7 10:57
 */

@Controller
@RequestMapping("/user")
public class UserController {


    @Autowired
    private IUserService userService;

    @Autowired
    private MessageProducer messageProducer;

    @RequestMapping("/findAll")
    public String findAll(Model model){
        List<User> userList = userService.findAll();
        model.addAttribute("userList",userList);
        return "user-list";
    }

    @RequestMapping("/send")
    @ResponseBody
    public String send(){
        messageProducer.sendMessage();
        return "ok";
    }
}
